package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.dtos.WmNewsDto;
import com.heima.model.common.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
@Slf4j
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 内容列表
     *
     * @param reqDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto reqDto){
        log.info("查询文章内容列表：{}",reqDto);
        return wmNewsService.pageQuery(reqDto);
    }

    /**
     * 发布文章
     *
     * @param wmNewsDto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto){
        //@RequestParam Boolean draft,
        //log.info("是否存为草稿：{}",draft);
        log.info("发布文章：{}",wmNewsDto);
        return wmNewsService.submit(wmNewsDto);
    }

    /**
     * 文章信息回显
     *
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult showNews(@PathVariable("id") Integer id){
        log.info("文章信息回显：{}",id);
        return wmNewsService.showNews(id);
    }

    /**
     * 删除文章
     *
     * @param id
     * @return
     */
    @GetMapping("/del_news/{id}")
    public ResponseResult delNews(@PathVariable("id") Integer id){
        log.info("删除文章：{}",id);
        return wmNewsService.delNews(id);
    }

    /**
     * 自媒体文章上下架
     *
     * @param wmNewsDto
     * @return
     */
    @PostMapping("down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto wmNewsDto){
        log.info("本次自媒体文章上下架操作：{}",wmNewsDto.getEnable() == 1 ? "上架":"下架");
        return wmNewsService.downOrUp(wmNewsDto);
    }
}
